#!/usr/bin/env python

import wx
import images

class Frame(wx.Frame):	
	def __init__(self, parent, id):
		wx.Frame.__init__(self, parent, id, title='Complete Frame')
		self.panel = wx.Panel(self) #Create panel
		self.panelBgColor = 'White'
		self.panel.SetBackgroundColour(self.panelBgColor)
		statusBar = self.CreateStatusBar()
		toolBar = self.CreateToolBar()
		toolBar.AddSimpleTool( wx.NewId(), images.getNewBitmap(),\
			"New", "Long help for 'New'")
		toolBar.Realize()
		
		menuBar = wx.MenuBar()
		menu1 = wx.Menu()
		menuBar.Append(menu1, "&File")
		menu2 = wx.Menu()
		menu2.Append ( wx.NewId(), "&Copy", "Copy in status bar" )
		menu2.Append ( wx.NewId(), "C&ut", "Cut in status bar" )
		menu2.Append ( wx.NewId(), "&Paste", "Paste in status bar" )
		menu2.AppendSeparator()
		menu2.Append ( wx.NewId(), "&Options...", "Display Options" )
		menuBar.Append ( menu2, "&Edit" )
		self.SetMenuBar(menuBar)
		
		self.button = wx.Button( self.panel, label="Close" ) #Create button
		self.Bind ( wx.EVT_BUTTON, self.OnButtonClick, self.button ) #Bind button click
		self.button.Bind ( wx.EVT_ENTER_WINDOW, self.OnEnterWindow )
		self.button.Bind ( wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow )
		self.button.Bind ( wx.EVT_LEFT_DOWN, self.OnLeftMouseDown )
		self.Bind ( wx.EVT_CLOSE, self.OnCloseWindow ) #Bind window close click
	
		self.button2 = wx.Button( self.panel, label="ListChoose",pos=(80,30) )
		self.Bind ( wx.EVT_BUTTON, self.OnButtonClick2, self.button2 )
		
	def OnCloseMe ( self, event ):
		self.Close ( True )
		
	def OnCloseWindow ( self, event ):
		self.Destroy()
	
	def OnButtonClick ( self, event ):
		dlg = wx.MessageDialog(None, "Are you ready to see the result?", "MessageDialog", wx.YES_NO | wx.ICON_QUESTION )
		result = dlg.ShowModal ()
		dlg.Destroy()
		print result
		if result == wx.ID_YES:
			if self.panelBgColor == 'Green':
				self.panelBgColor = 'White'
			else:
				self.panelBgColor = 'Green'
			self.panel.SetBackgroundColour ( self.panelBgColor )
			self.panel.Refresh()
		
	def OnEnterWindow ( self, event ):
		self.button.SetLabel ( "Click me" )
		event.Skip()
		
	def OnLeaveWindow ( self, event ):
		dlg = wx.TextEntryDialog ( None, "Please enter your name to check the result.", 'Your Name', 'WHQ')
		if dlg.ShowModal() == wx.ID_OK and dlg.GetValue() == 'JINYE':
			self.button.SetLabel ( "Leave me" )
		print ( 'what you input is ' + dlg.GetValue() )
		dlg.Destroy()
		
		event.Skip()
	
	def OnLeftMouseDown ( self, event ):
		self.button.SetLabel ( "Mouse Down" )
		event.Skip ( ) #If we comment out this, then "OnButtonClick" can't be reached.
	
	def OnButtonClick2 ( self, event ):
		list = []
		for count in range(100,999):
			list.append(str(count))
		dlg = wx.SingleChoiceDialog ( None, 'Choose a number:', 'Single Choose', list )
		if dlg.ShowModal() == wx.ID_OK:
			reponse = dlg.GetStringSelection()
			print ('what your choose is ' + reponse)
			print ('what your choose index is ' + str(dlg.GetSelection()) )
		dlg.Destroy()
		
class App(wx.App):
	def __init__(self, redirect=True, filename=None):
		wx.App.__init__(self, redirect, filename)
		
	def OnInit(self):
		self.frame = Frame(parent=None, id=-1)
		self.frame.Show()
		self.SetTopWindow(self.frame)
		
		return True

	def OnExit(self):
		pass


def main():
	app = App(redirect=True)
	app.MainLoop()
	
if __name__ == '__main__':
	main()
	
